<script>
  Array.prototype.myReduce = function (callbacked, initValue) {
    let startIndex = initValue ? 0 : 1
    let sum = initValue || this[0]
    for (let i = startIndex; i < this.length; i++) {
     sum =  callbacked(sum,this[i],i,this)
    }
    return sum
  }
  const arr = [1, 2, 3, 4]
  console.log(arr.myReduce((sum, item) => sum + item, 0))
</script>